class Student(object): # 所有类都继承自object类
    def __init__(self, name, age, score):
        self.__name = name
        self.__age = age
        self.__score = score
    
    def get_name(self):
        return self.__name
    def get_age(self):
        return self.__age
    def get_score(self):
        return self.__score
    def set_name(self, name):
        self.__name = name
    def set_age(self,age):
        self.__age = age
    def set_score(self,score):
        self.__score = score
    
    def print_score(self):
        print("%s : %d" % (self.__name, self.__score))
        
    def get_rank(self):
        if self.__score >= 90:
            return 'A'
        elif self.__score >= 80:
            return "B"
        elif self.__score >= 60:
            return "C"
        else:
            return "D"
        
stu=Student('ben',19,95) # 创建实例stu，与__init__方法相关
print("Name:%s,Age:%d,Score:%d" % (stu.get_name(),stu.get_age(),stu.get_score()))
stu.print_score() # ben : 95
print(stu.get_rank()) # A

class Animal(object):
    def run(self):
        print('Animal is running...')

class Dog(Animal): # 继承自Animal类
    def run(self):
        super().run()
        print("And I am a dog.Wang Wang Wang...")
        
class Cat(Animal): # 继承自Animal类
    def run(self):
        super().run()
        print("And I am a cat.Miaow Miaow Miaow...")
        
a=Animal()
a.run()
d=Dog()
d.run()
c=Cat()
c.run()

def fn():
    print("fn")
print(type(123)) # <class 'int'>
print(type('ABC')) # <class 'str'>
print(type(True)) # <class 'bool'>
print(type(abs)) # <class 'builtin_function_or_method'>
print(type(fn)) # <class 'function'>

import types
print(type(123)==int) # True
print(type('abc')==str) # True
print(type(abs)==types.BuiltinFunctionType) # True，内置函数
print(type(fn)==types.FunctionType) # True，用户定义函数

isinstance(d,object) # True
isinstance(d,Animal) # True
isinstance(d,Dog) # True
isinstance(d,Cat) # False

# print(dir('ABC'))

print(hasattr(stu,'__age')) # False
print(hasattr(stu,'_Student__age')) # True
print(getattr(stu,'_Student__age')) # 19
setattr(stu,'_Student__age', 20)
print(getattr(stu,'_Student__age')) # 20
# 等价于
print(stu._Student__age) # type: ignore
